package com.pic.others.mq;


import com.pic.common.constants.MqConstants;
import com.pic.others.mq.message.EmailMessage;
import com.pic.others.service.ICodeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * 先占坑位
 */
@RequiredArgsConstructor
@Component
@Slf4j
public class SendInformationListerner {

    private final ICodeService codeService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "qa.email.queue", durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.SMS_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.SMS_MESSAGE
    ))
    public void sendEmail(EmailMessage emailMessage){
        log.info("你接受了数据好吓人;{},{}",emailMessage.getEmail(),emailMessage.getPrefix());
        codeService.sendVerifyCode(emailMessage.getEmail(),emailMessage.getPrefix());
    }
}
